//
//  ToastViewController.m
//  test
//
//  Created by mac on 2017/9/15.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ToastViewController.h"
#import <MBProgressHUD/MBProgressHUD.h>

@interface ToastViewController ()
@property (atomic, assign) BOOL canceled;

@end
MBProgressHUD *hud;
@implementation ToastViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    UIButton *show = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    CGRect frame0;
    frame0.size.width = 150;
    frame0.size.height = 40;
    frame0.origin.x = self.view.frame.size.width / 2 - 75;
    frame0.origin.y = self.view.frame.size.height / 2;
    [show setFrame:frame0];
    [show setTitle:@"show" forState:UIControlStateNormal];
    [show addTarget:self action:@selector(show) forControlEvents:UIControlEventTouchUpInside];
    [show setBackgroundColor:[UIColor orangeColor]];
    [show setAlpha:0.8];
    show.layer.cornerRadius=5;
    [show setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:show];
}

-(void)show{
    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    /*hud.mode = MBProgressHUDModeAnnularDeterminate;
    hud.label.text = @"Loading";*/
    
    //hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");
    
    /*hud.mode = MBProgressHUDModeDeterminate;
    hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");
    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
        [self doSomeWorkWithProgress];
        dispatch_async(dispatch_get_main_queue(), ^{
            [hud hideAnimated:YES];
        });
    });*/
    
    
    
   //[self performSelector:@selector(hide) withObject:self afterDelay:2];
}


- (void)doSomeWorkWithProgress {
    self.canceled = NO;
    float progress = 0.0f;
    while (progress < 1.0f) {
        if (self.canceled) break;
        progress += 0.01f;
        dispatch_async(dispatch_get_main_queue(), ^{
           hud.progress = progress;
        });
        usleep(50000);
    }
}

-(void)hide{
    [hud hideAnimated:YES];
    //[hud hideHUDForView:self.view animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
